home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
hity wydania
/
Ubuntu 9.10 PL
/
karmelkowy-koliberek-desktop-9.10-i386-PL.iso
/
casper
/
filesystem.squashfs
/
usr
/
bin
/
update-pciids
< prev
next >
Wrap
Text File
|
2009-10-05
|
3KB
|
147 lines
#!/bin/sh
# update-pciids.sh is licensed under the GNU General Public License
# (GPL) version 2 or above.
#
# Copyright (C) 2008 Anibal Monsalve Salazar <anibal@debian.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Please read the "COPYING" file in the archive root, or visit
# http://www.gnu.org/licenses/gpl.html, for information about the GPL.
#
# This scipt is a rewrite of a script with the same name by
# Martin Mares.
set -e
URL="http://pciids.sourceforge.net/v2.2/pci.ids"
FILE=/usr/share/misc/pci.ids
RM="/bin/rm"
MV="/bin/mv"
SED="/bin/sed"
GREP="/bin/grep"
GZIP="/bin/gzip"
ECHO="/bin/echo"
CHMOD="/bin/chmod"
GUNZIP="/bin/gunzip"
BUNZIP2="/bin/bunzip2"
TOUCH="/usr/bin/touch"
PERL="/usr/bin/perl"
WGET="/usr/bin/wget"
CURL="/usr/bin/curl"
LYNX="/usr/bin/lynx"
NEWFILE="$FILE.new"
OLDFILE="$FILE.old"
if [ "$1" = "-q" ]
then
quiet="yes"
else
quiet="no"
fi
if ! $TOUCH $NEWFILE > /dev/null 2>&1
then
$ECHO >&2 "update-pciids: $NEWFILE is read-only"
exit 1
fi
[ -f $NEWFILE ] && $RM $NEWFILE
[ -f $NEWFILE.bz2 ] && $RM $NEWFILE.bz2
[ -f $NEWFILE.gz ] && $RM $NEWFILE.gz
if [ -x $BUNZIP2 ]
then
EXT=".bz2"
UNZIP=$BUNZIP2
elif [ -x $GUNZIP ]
then
EXT=".gz"
UNZIP=$GUNZIP
else
$ECHO >&2 "update-pciids: cannot find bunzip2 or gunzip"
exit 1
fi
if [ -x $WGET ]
then
$WGET -nv -O $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
elif [ -x $CURL ]
then
$CURL -o $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
elif [ -x $LYNX ]
then
$LYNX -source $URL$EXT > $NEWFILE$EXT
else
$ECHO >&2 "update-pciids: cannot find wget, curl or lynx"
exit 1
fi
$UNZIP < $NEWFILE$EXT > $NEWFILE
$RM $NEWFILE$EXT
if ! $GREP > /dev/null "^C " $NEWFILE
then
$ECHO >&2 "update-pciids: missing class info, probably truncated file"
exit 1
fi
date=$($GREP "^#.*Date:" $NEWFILE 2> /dev/null | $SED "s/^#.*Date://")
if [ -z "$date" ]
then
$ECHO >&2 "update-pciids: missing snapshot date, probably truncated file"
exit 1
fi
# Reduce by removing subsystem ids and comments
if [ -n "$BASH_VERSION" ]
then
#$GREP -Ev ^$'\t\t'"|^\s*$|^\s*#" $NEWFILE | $GZIP -9 > $NEWFILE.gz
$GREP -Ev ^$'\t\t'"|^\s*$|^\s*#" $NEWFILE > $NEWFILE.tmp
mv $NEWFILE.tmp $NEWFILE
else
#$PERL -ne 'print unless /^(\s*#|\s*$|\t\t)/' < $NEWFILE | $GZIP -9 > $NEWFILE.gz
$PERL -ne 'print unless /^(\s*#|\s*$|\t\t)/' < $NEWFILE > $NEWFILE.tmp
mv $NEWFILE.tmp $NEWFILE
fi
#$RM $NEWFILE
if [ -f $FILE ]
then
[ -f $OLDFILE ] && $RM $OLDFILE
$MV $FILE $OLDFILE
fi
$MV $NEWFILE $FILE
$TOUCH -d "$date" $FILE
if [ -f $FILE.gz ]
then
#$CHMOD -f --reference=$FILE.gz $NEWFILE.gz 2> /dev/null || true
[ -f $OLDFILE.gz ] && $RM $OLDFILE.gz
$MV $FILE.gz $OLDFILE.gz
fi
#$MV $NEWFILE.gz $FILE.gz
#$TOUCH -d "$date" $FILE.gz
if [ $quiet = "no" ]
then
$ECHO "Downloaded daily snapshot dated $date"
fi
exit 0